package com.bjsxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bjsxt.commons.pojo.BaizhanResult;
import com.bjsxt.mapper.TbItemParamItemMapper;
import com.bjsxt.pojo.TbItemParamItem;
import com.bjsxt.service.ItemParamItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author coder_z
 * @date 2023/2/9
 **/
@Service
public class ItemParamItemImpl implements ItemParamItemService {
    @Autowired
    private TbItemParamItemMapper tbItemParamItemMapper;
    /**
     * 商品规格参数新增
     * @param itemParamItem
     * @return
     */
    @Transactional
    @Override
    public BaizhanResult insert(TbItemParamItem itemParamItem) {
       int index= tbItemParamItemMapper.insert(itemParamItem);
        if (index==1) {
            return BaizhanResult.ok();
        }
        return BaizhanResult.error("服务器端消息-新增失败");
    }

    @Override
    public BaizhanResult selectById(long itemId) {
//      查询到对应的列
        QueryWrapper<TbItemParamItem> wrapper = new QueryWrapper<TbItemParamItem>().eq("item_id", itemId);
        TbItemParamItem tbItemParamItem = tbItemParamItemMapper.selectOne(wrapper);
        if(tbItemParamItem!=null){
            return BaizhanResult.ok(tbItemParamItem);
        }
        return  BaizhanResult.error("服务器端消息-未查询到商品规格参数");
    }

    @Override
    public BaizhanResult updateByItemId(TbItemParamItem paramItem) {
        QueryWrapper<TbItemParamItem> wrapper = new QueryWrapper<TbItemParamItem>().eq("item_id", paramItem.getItemId());
        int index = tbItemParamItemMapper.update(paramItem, wrapper);
        if(index==1){
            return BaizhanResult.ok();
        }
        return BaizhanResult.error("服务器端消息-修改商品规格参数信息失败");
    }
}
